/**   
* @Title: MailUtil.java 
* @Package com.leesche.zcsp.node.communication.util 
* @Description:() 
* @author dennies yang
* @date 2016年10月18日 下午3:47:28 
* @version V1.0   
*/
package com.leesche.zcsp.node.communication.util;

import com.leesche.zcsp.node.pay.wecha.data.Message;
import org.apache.log4j.Logger;

import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Date;
import java.util.Properties;

/**
 * @Title: MailUtil.java
 * @Package com.leesche.zcsp.node.communication.util
 * @Description:()
 * @author dennies yang
 * @date 2016年10月18日 下午3:47:28
 * @version V1.0
 */
public class MailUtil {
	private static final Logger logger = Logger.getLogger(MailUtil.class);

	/**
	 * 
	 * @throws MessagingException 
	 * @throws AddressException 
	 * @Title: sendMail @Description: TODO(邮件发送) @param @param toMail
	 * 到达的邮箱 @param @param valid 验证码 @param @return @return
	 * Message<String> @throws
	 */
	public static Message<String> sendMail(String toMail, String valid) throws MessagingException {
		Properties props = null;

	    props = new Properties();
	    props.setProperty("mail.transport.protocol", "smtp");
	    props.setProperty("mail.smtp.host", "smtp.exmail.qq.com");
	    props.setProperty("mail.smtp.port", "25");
	    props.setProperty("mail.smtp.auth", "true");
	    props.setProperty("mail.debug", "true");

	    String from = "password@yiyachina.com.cn";
	    String to = "258074945@qq.com";
	    Session session = Session.getDefaultInstance(props);

	    MimeMessage message = new MimeMessage(session);

	    message.setFrom(new InternetAddress(from));

	    message.setSubject("360EBM员享会密码重置");

	    message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(to));

	    message.setSentDate(new Date());

	    message.setText("adasd");

	    message.saveChanges();

	    Transport transport = session.getTransport();

	    transport.connect("password@yiyachina.com.cn", "yiya1213");

	    transport.sendMessage(message, message.getAllRecipients());

	    transport.close();
		return null;
	}

}
